import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { PosterService } from '../../services/admin/poster.service';

/**
 * PosterController
 * 对应 PHP: Poster Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('sys')
@Controller('adminapi/sys')
export class PosterController {
  constructor(private readonly posterService: PosterService) {}

  /**
   * 自定义海报
   * 路由: GET poster
   * PHP路由: Route::get('poster', 'sys.Poster/pages')
   */
  @Get('poster')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '自定义海报' })
  async pages(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: pages

      return await this.posterService.getPage(data);
    } catch (error) {
      throw new BusinessException('pages操作失败', error);
    }
  }

  /**
   * 自定义海报
   * 路由: GET poster/list
   * PHP路由: Route::get('poster/list', 'sys.Poster/lists')
   */
  @Get('poster/list')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '自定义海报' })
  async lists(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: lists

      return await this.posterService.getList(data);
    } catch (error) {
      throw new BusinessException('lists操作失败', error);
    }
  }

  /**
   * 自定义海报
   * 路由: GET poster/:id
   * PHP路由: Route::get('poster/:id', 'sys.Poster/info')
   */
  @Get('poster/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '自定义海报' })
  async info(@Param('id') id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: info

      return await this.posterService.getInfo(id);
    } catch (error) {
      throw new BusinessException('info操作失败', error);
    }
  }

  /**
   * 自定义海报
   * 路由: POST poster
   * PHP路由: Route::post('poster', 'sys.Poster/add')
   */
  @Post('poster')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '自定义海报' })
  async add(@Body() data: AddDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: add

      return await this.posterService.add(data);
    } catch (error) {
      throw new BusinessException('add操作失败', error);
    }
  }

  /**
   * 自定义海报
   * 路由: PUT poster/:id
   * PHP路由: Route::put('poster/:id', 'sys.Poster/edit')
   */
  @Put('poster/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '自定义海报' })
  async edit(
    @Param('id') id: string,
    @Body() data: EditDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: edit

      return await this.posterService.edit(id, data);
    } catch (error) {
      throw new BusinessException('edit操作失败', error);
    }
  }

  /**
   * 自定义海报
   * 路由: DELETE poster/:id
   * PHP路由: Route::delete('poster/:id', 'sys.Poster/del')
   */
  @Delete('poster/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '自定义海报' })
  async del(@Param('id') id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: del

      return await this.posterService.del(id);
    } catch (error) {
      throw new BusinessException('del操作失败', error);
    }
  }

  /**
   * 自定义海报
   * 路由: PUT poster/status
   * PHP路由: Route::put('poster/status', 'sys.Poster/modifyStatus')
   */
  @Put('poster/status')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '自定义海报' })
  async modifyStatus(@Body() data: ModifyStatusDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: modifyStatus

      return await this.posterService.modifyStatus(data);
    } catch (error) {
      throw new BusinessException('modifyStatus操作失败', error);
    }
  }

  /**
   * 自定义海报
   * 路由: PUT poster/default
   * PHP路由: Route::put('poster/default', 'sys.Poster/modifyDefault')
   */
  @Put('poster/default')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '自定义海报' })
  async modifyDefault(@Body() data: ModifyDefaultDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: modifyDefault

      return await this.posterService.modifyDefault(data);
    } catch (error) {
      throw new BusinessException('modifyDefault操作失败', error);
    }
  }

  /**
   * 自定义海报
   * 路由: GET poster/type
   * PHP路由: Route::get('poster/type', 'sys.Poster/type')
   */
  @Get('poster/type')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '自定义海报' })
  async type(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: type

      return await this.posterService.getType(data['type']);
    } catch (error) {
      throw new BusinessException('type操作失败', error);
    }
  }

  /**
   * 自定义海报
   * 路由: GET poster/template
   * PHP路由: Route::get('poster/template', 'sys.Poster/template')
   */
  @Get('poster/template')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '自定义海报' })
  async template(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: template

      return await this.posterService.getTemplateList(
        data['addon'],
        data['type'],
      );
    } catch (error) {
      throw new BusinessException('template操作失败', error);
    }
  }

  /**
   * 自定义海报
   * 路由: GET poster/init
   * PHP路由: Route::get('poster/init', 'sys.Poster/init')
   */
  @Get('poster/init')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '自定义海报' })
  async init(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: init

      return await this.posterService.getInit(params);
    } catch (error) {
      throw new BusinessException('init操作失败', error);
    }
  }

  /**
   * 自定义海报
   * 路由: GET poster/preview
   * PHP路由: Route::get('poster/preview', 'sys.Poster/preview')
   */
  @Get('poster/preview')
  @ApiOperation({ summary: '自定义海报' })
  async preview() {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: preview
      // 服务方法名解析失败，需要手动实现
      return { message: 'preview - 服务方法名解析失败，需要手动实现' };
    } catch (error) {
      throw new BusinessException('preview操作失败', error);
    }
  }
}
